package com.rchat.pocmini.activity.groupmember;

import android.view.View;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.airtalkee.sdk.AirtalkeeAccount;
import com.rchat.pocmini.R;
import com.rchat.pocmini.activity.fragment.groups.GroupsPresenterImpl;
import com.rchat.pocmini.bean.QueryGroupMemberBean;
import com.rchat.pocmini.common.mvp.BaseMvpActivity;

import java.util.ArrayList;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * Created by ljd on 2017/9/7.
 */

public class GroupMemberMvpActivity extends BaseMvpActivity<GroupMemberPresenterImpl,GroupMemberModelImpl> implements GroupMemberContract.View{

    @BindView(R.id.rl_showmenbers)
    RelativeLayout mRlShowMembers;

    @BindView(R.id.tv_toltal)
    TextView mTvTotal;

    @BindView(R.id.iv_back)
    ImageView ivBack;

    @BindView(R.id.tv_group_name)
    TextView tvGroupName;

    @BindView(R.id.exit_group)
    View mBTNExitGroup;


    @BindView(R.id.lv_allmenber)
    ListView mLvGroupMember;

    private ArrayList<QueryGroupMemberBean.DataBean.ChatMembersBean> data;
    private GroupMemberAdapter adapter;


    @Override
    public void initPresenter() {
        mPresenter.setVM(this,mModel);
        data = new ArrayList<>();
        adapter = new GroupMemberAdapter(this,data);
    }

    @Override
    public int getLayoutId() {
        return R.layout.group_member_activity_layout;
    }

    @Override
    public void initView() {
        mLvGroupMember.setAdapter(adapter);
        tvGroupName.setText(getIntent().getStringExtra("groupName"));
    }

    @Override
    public void doAfterInitView() {
        mPresenter.queryGroupMember(getIntent().getStringExtra(GroupsPresenterImpl.KEY_GROUPID));
    }


    @Override
    public void showGroupMemberListView(ArrayList<QueryGroupMemberBean.DataBean.ChatMembersBean> data) {
        this.data.clear();
        this.data.addAll(data);
        adapter.notifyDataSetChanged();
    }


    @OnClick({R.id.iv_back,
            R.id.exit_group})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.iv_back:
                finish();
                break;
            case R.id.exit_group:
                mPresenter.delGroup(getIntent().getStringExtra(GroupsPresenterImpl.KEY_GROUPID));
        }
    }

}
